package transaction.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import transaction.model.User;
import transaction.model.UserLog;
import transaction.service.UserLogService;
import transaction.service.UserService;

/**
 * @Author quan
 * @Description TODO
 * @Date 2023/7/31 11:13
 */

@RestController
@RequestMapping("/trans1")
public class UserLogController {
    @Autowired
    private UserService userService;
    @Autowired
    private UserLogService userLogService;
    //事务定义
    @Transactional
    @RequestMapping("/addUser1")
    public boolean addUser1(String username,String password){
        //插入用户表
        User user = new User(username,password);
        userService.insert(user);
        //插入用户日志表
        UserLog userLog = new UserLog(username);
        userLogService.insertLog(userLog);
        return true;
    }
}
